﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ControlPresupuesto
{
    public partial class FrmSolicitudCompromisoHistorico : Form
    {
        public FrmSolicitudCompromisoHistorico(string CodSolicitud)
        {
            InitializeComponent();

            this.tittle.Text = "Historico Solicitud de Compromiso " + CodSolicitud;

            // --- Cargo los usuarios
            this.spSeguridadUsuarioTableAdapter.Fill(this.controlPresupuestoDataSet.spSeguridadUsuario);

            // Cargo el historico de la solicitud de compromiso
            this.spCompromisoSolicitud_HistorialTableAdapter.FillBy(
                this.controlPresupuestoDataSet.spCompromisoSolicitud_Historial,
                "SelectByCodSolicitud",
                null,
                null,
                CodSolicitud,
                null,
                null,
                null,
                null
                );
        }
        
        private void FrmSolicitudCompromiso_Historico_Load(object sender, EventArgs e)
        {

        }
        
        #region Eventos asociados a los botones del BindingNavigator

        private void exportar_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try { Utils.get().exportar(this.spCompromisoSolicitud_HistorialDataGridView); }
            catch (Exception ex) { MessageException.show(ex); }
            Cursor.Current = Cursors.Default;
        }


        private void filter_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            BindingSource bs = ((BindingNavigator)((ToolStripButton)sender).GetCurrentParent()).BindingSource;
            try
            {
                bs.RemoveFilter();
                this.toolStripTextBox1.Text = string.Empty;
            }
            catch (Exception ex)
            {
                MessageException.show(ex);
                bs.CancelEdit();
            }
            Cursor.Current = Cursors.Default;
        }

        private void filterText_TextChanged(object sender, EventArgs e)
        {

            Cursor.Current = Cursors.WaitCursor;
            BindingSource bs = ((BindingNavigator)((ToolStripTextBox)sender).GetCurrentParent()).BindingSource;
            DataTable table = ((DataSet)bs.DataSource).Tables[bs.DataMember];
            ToolStripTextBox tb = (ToolStripTextBox)sender;
            try
            {
                String filtro = "";
                foreach (DataColumn cl in table.Columns)
                {
                    filtro += "ISNULL(" + cl.ColumnName.ToString() + ",'')+' '+";
                }
                filtro = filtro.Substring(0, filtro.Length - 5);
                filtro += " like'%" + tb.Text + "%'";
                //MessageBox.Show(filtro);
                bs.Filter = filtro;
            }
            catch (Exception ex)
            {
                MessageException.show(ex);
                bs.CancelEdit();
            }
            Cursor.Current = Cursors.Default;
        }

        #endregion
    }
}
